export default {
  methods: {
    //批量提交审核
    async handleBatchSubmitAudit(list, flowType = 1) {
      let filterData = list.filter(
        (v) => v.auditStatus == 0 || v.auditStatus == 3,
      )
      if (filterData.length == 0) {
        this.warnMsg('暂无需要提交审核的数据')
        return
      }
      // let obj = {
      //   auditReason: '',
      //   auditStatus: 1,
      //   status: 0,
      //   ids: filterData.map((v) => v.id),
      // }
      // await this.$store.dispatch('changeAuditStatusBatchNewsContents', obj)
      this.flowSubmit(filterData, flowType)
    },
    //提交审核
    async flowSubmit(list, flowType) {
      let arr = []
      list.forEach((item) => {
        arr.push({
          businessData: JSON.stringify(item), //业务数据 json字符串
          businessKey: item.id, //资源id
          definitionCode: flowType, //1.书籍审核 2.新闻审核
          scope: 1,
        })
      })
      await this.$store.dispatch('submitFlowApi', arr)
      this.batchChangeState(list)
    },
    //修改状态
    async batchChangeState(list) {
      let obj = {
        auditReason: '',
        auditStatus: 1,
        status: 0,
        ids: list.map((v) => v.id),
      }
      await this.$store.dispatch('changeAuditStatusBatchNewsContents', obj)
      this.$bus.$emit('refreshNewsContentsList')
      this.successMsg('操作成功')
    },
    //取回
    async handleTakeBack(row, flowType = 1) {
      let businessKey = flowType + ':' + row.id
      let res = await this.$store.dispatch('takeBackFlowRunTask', {
        businessKey,
      })
      if (res.msg != '成功') {
        this.warnMsg(res.msg)
        return
      }
      let obj = { id: row.id, status: 0, auditStatus: 0 }
      await this.$store.dispatch('updateNewsContents', obj)
      this.getList()
      this.successMsg('操作成功')
    },
  },
}
